/**
 * Copyright 2007 Igor Chaves Cananéa
 *
 * This file is part of PBSFW
 *
 * PBSFW is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * PBSFW is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef _SIMULATION_EVENT_H_
#define _SIMULATION_EVENT_H_

#include <string>
#include <set>
#include <list>
#include "defines.h"
#include "process.h"
#include "simevent.h"
using namespace std;

namespace pbsfw {
    class SimulationEvent : public SimEvent {
        private:
            set<Process*> waitqueue;

        protected:
            bool occurred;

        public:
            SimulationEvent(string name);
            SimulationEvent(const SimulationEvent &e) : SimEvent(e) {}

            bool hasOccurred() const {
                return this->occurred;
            }

            void signal();
            void wait(Process &p) {
                p.setActive(false);
                this->waitqueue.insert(&p);
            }

            void removeProcess(Process &p) {
                set<Process*>::iterator itr = this->waitqueue.find(&p);
                if (itr != this->waitqueue.end()) {
                    this->waitqueue.erase(itr);
                }
            }

            void reset() {
                this->waitqueue.clear();
                this->occurred = false;
            }

            void clear() {
                this->occurred = false;
            }
    };
};

#endif

